package com.android.music.view;

import com.android.music.R;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

public class SpectrumView extends View {

	public static final int spectrumNum = 24;

	public static final int blockleftmargin = 50;
	public static final int blockbottommargin = 50;
	public static final int blockwidth = 10;
	public static final int blockheight = 5;
	public static final int blockgap = 1;

	private Paint paint;
	
	private Rect[] rect = new Rect[spectrumNum];

	private int[] spectrumdata = {10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10};

	public SpectrumView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public SpectrumView(Context context, AttributeSet attr) {
		super(context, attr);
		paint = new Paint();
		paint.setColor(getResources().getColor(R.color.blue));
		paint.setStyle(Style.FILL);
		
		initRect();
	}
	
	private void initRect() {
		// TODO Auto-generated method stub
		for (int i = 0; i < spectrumNum; i++) {
			rect[i] = new Rect();
			rect[i].left = blockleftmargin + (blockwidth + blockgap) * i;
			rect[i].top = blockbottommargin + spectrumdata[i];
			rect[i].right = rect[i].left + blockwidth;
			rect[i].bottom = blockbottommargin + spectrumdata[i];
		}
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		for (int i = 0; i < spectrumNum; i++) {
			canvas.drawRect(rect[i], paint);
		}
	}
}
